home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / nfsrc21.zip / ACCTQTR.PRG < prev    next >
Text File  |  1992-09-28  |  5KB  |  140 lines

  1. /*
  2.  * File......: ACCTQTR.PRG
  3.  * Author....: Jo W. French dba Practical Computing
  4.  * CIS ID....: 74731,1751
  5.  * Date......: $Date:   28 Sep 1992 00:26:30  $
  6.  * Revision..: $Revision:   1.3  $
  7.  * Log file..: $Logfile:   C:/nanfor/src/acctqtr.prv  $
  8.  * 
  9.  * The functions contained herein are the original work of Jo W. French
  10.  * and are placed in the public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log:   C:/nanfor/src/acctqtr.prv  $
  16.  * 
  17.  *    Rev 1.3   28 Sep 1992 00:26:30   GLENN
  18.  * Jo French clean up.
  19.  * 
  20.  *    Rev 1.2   15 Aug 1991 23:02:36   GLENN
  21.  * Forest Belt proofread/edited/cleaned up doc
  22.  * 
  23.  *    Rev 1.1   14 Jun 1991 19:50:44   GLENN
  24.  * Minor edit to file header
  25.  * 
  26.  *    Rev 1.0   01 Apr 1991 01:00:26   GLENN
  27.  * Nanforum Toolkit
  28.  *
  29.  */
  30.  
  31. /*  $DOC$
  32.  *  $FUNCNAME$
  33.  *     FT_ACCTQTR()
  34.  *  $CATEGORY$
  35.  *     Date/Time
  36.  *  $ONELINER$
  37.  *     Return accounting quarter data
  38.  *  $SYNTAX$
  39.  *     FT_ACCTQTR( [ <dGivenDate> ], [ <nQtrNum> ] ) -> aDateinfo
  40.  *  $ARGUMENTS$
  41.  *     <dGivenDate> is any valid date in any date format.  Defaults
  42.  *     to current system date if not supplied.
  43.  *
  44.  *     <nQtrNum> is a number from 1 to 4 signifying a quarter.
  45.  *     Defaults to current quarter if not supplied.
  46.  *  $RETURNS$
  47.  *     A three element array containing the following data:
  48.  *
  49.  *        aDateInfo[1] - The year and qtr. as a character string "YYYYQQ"
  50.  *        aDateInfo[2] - The beginning date of the accounting quarter
  51.  *        aDateInfo[3] - The ending date of the accounting quarter
  52.  *  $DESCRIPTION$
  53.  *     FT_ACCTQTR() creates an array containing data about the
  54.  *     accounting quarter containing the given date.
  55.  *
  56.  *     An accounting period has the following characteristics:
  57.  *
  58.  *     If the first week of the period contains 4 or more 'work'
  59.  *     days, it is included in the period; otherwise, the first
  60.  *     week was included in the prior period.
  61.  *
  62.  *     If the last week of the period contains 4 or more 'work'
  63.  *     days it is included in the period; otherwise, the last week
  64.  *     is included in the next period.  This results in 13 week
  65.  *     'quarters' and 4 or 5 week 'months'.  Every 5 or 6 years, a
  66.  *     'quarter' will contain 14 weeks and the year will contain 53
  67.  *     weeks.
  68.  *  $EXAMPLES$
  69.  *     // get info about accounting month containing 9/15/90
  70.  *     aDateInfo := FT_ACCTQTR( CTOD("09/15/90") )
  71.  *     ? aDateInfo[1]   //  199003       (3rd quarter)
  72.  *     ? aDateInfo[2]   //  07/01/90     beginning of quarter 3
  73.  *     ? aDateInfo[3]   //  09/29/90     end of quarter 3
  74.  *
  75.  *     // get info about accounting qtr. 2 in year containing 9/15/90
  76.  *     aDateInfo := FT_ACCTQTR( CTOD("09/15/90"), 2 )
  77.  *     ? aDateInfo[1]   //  199002
  78.  *     ? aDateInfo[2]   //  04/01/89   beginning of quarter 2
  79.  *     ? aDateInfo[3]   //  06/30/90   end of quarter 2
  80.  *  $SEEALSO$
  81.  *     FT_DATECNFG() FT_ACCTWEEK() FT_ACCTMONTH() FT_ACCTYEAR()
  82.  *  $END$
  83. */
  84.  
  85. FUNCTION FT_ACCTQTR(dGivenDate,nQtrNum)
  86.   LOCAL nYTemp, nQTemp, lIsQtr, aRetVal
  87.  
  88.   IF ! ( VALTYPE(dGivenDate) $ 'ND' )
  89.     dGivenDate := DATE()
  90.   ELSEIF VALTYPE(dGivenDate) == 'N'
  91.     nQtrNum    := dGivenDate
  92.     dGivenDate := DATE()
  93.   ENDIF
  94.   aRetVal    := FT_QTR(dGivenDate)
  95.   nYTemp     := VAL(SUBSTR(aRetVal[1],1,4))
  96.   nQTemp     := VAL(SUBSTR(aRetVal[1],5,2))
  97.   aRetVal[2] := FT_ACCTADJ(aRetVal[2])
  98.   aRetVal[3] := FT_ACCTADJ(aRetVal[3], .T. )
  99.  
  100.   IF dGivenDate < aRetVal[2]
  101.     dGivenDate := FT_MADD(dGivenDate, -1)
  102.     aRetVal    := FT_QTR(dGivenDate)
  103.     nQTemp     -= 1
  104.     IF nQTemp  == 0
  105.        nYTemp  -= 1
  106.        nQTemp  := 4
  107.     ENDIF
  108.     aRetVal[2] := FT_ACCTADJ(aRetVal[2])
  109.     aRetVal[3] := FT_ACCTADJ(aRetVal[3], .T. )
  110.  
  111.   ELSEIF dGivenDate > aRetVal[3]
  112.  
  113.     dGivenDate := FT_MADD(dGivenDate,1)
  114.     aRetVal    := FT_QTR(dGivenDate)
  115.     nQTemp     += 1
  116.     IF nQTemp  == 5
  117.        nYTemp  += 1
  118.        nQTemp  := 1
  119.     ENDIF
  120.     aRetVal[2] := FT_ACCTADJ(aRetVal[2])
  121.     aRetVal[3] := FT_ACCTADJ(aRetVal[3], .T. )
  122.  
  123.   ENDIF
  124.  
  125.   lIsQtr     := ( VALTYPE(nQtrNum) == 'N' )
  126.   IF lIsQtr
  127.     IF( nQtrNum < 1 .OR. nQtrNum > 4 , nQtrNum := 4, )
  128.     aRetVal    := FT_QTR(dGivenDate, nQtrNum)
  129.     nYTemp     := VAL(SUBSTR(aRetVal[1],1,4))
  130.     nQTemp     := VAL(SUBSTR(aRetVal[1],5,2))
  131.     aRetVal[2] := FT_ACCTADJ(aRetVal[2])
  132.     aRetVal[3] := FT_ACCTADJ(aRetVal[3], .T. )
  133.   ENDIF
  134.  
  135.   aRetVal[1] := STR(nYTemp,4) + PADL(LTRIM(STR(nQTemp,2)), 2, '0')
  136.  
  137. RETURN aRetVal
  138.  
  139.  
  140.